﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Odyssey.Linq;
using Odyssey.Web.Models;

namespace Odyssey.Web.Controllers
{
    public class SubClassController : FrontBaseController
    {
        public ActionResult List(int? id)
        {
            tb_subclass subclass = GetTable<tb_subclass>().FirstOrDefault(item => item.Id == id.GetValueOrDefault());
            ViewData.Model = subclass;
            //if ((subclass.parentid ?? 0) == 0)//顶级subclass 或者说第二级分类
            //{
            //    BindMasterViewData(subclass.TopClassId);
            //    List<tb_subclass> subclasses = GetTable<tb_subclass>().Where(item => item.parentid == id.GetValueOrDefault()).ToList();
            //    ViewBag.SubClasses = subclasses;
            //    return View();
            //}

            List<tb_article> articles = GetTable<tb_article>().Where(item => item.ClassId == id.GetValueOrDefault()).ToList();
            ViewBag.Articles = articles.OrderBy(c => c.Order).ToList();
            BindMasterViewData(subclass.TopClassId);
            return View();
        }
    }
}
